package com.wutao.panzh.admin.content.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.panzh.UtilEntity.ResultVO;
import com.panzh.entity.HotelClassification;
import com.panzh.entity.SceneryClassification;
import com.panzh.myconst.ClassificationConst;
import com.wutao.panzh.service.HotelClassificationService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class HotelClassificationController {

    @Reference
    private HotelClassificationService hotelClassificationService;

//    get/all/hotel/classification
    @RequestMapping("/get/all/hotel/classification")
    @ResponseBody
    public ResultVO getAllHotelClassification(){
        List<HotelClassification> results = hotelClassificationService.getAllClassIfication();
        return new ResultVO<List<HotelClassification>>(ResultVO.SUCCESS,ResultVO.NO_MSG,results);
    }

    @RequestMapping("/sava/hotel/classification")
    @ResponseBody
    public ResultVO savaHotelClassification(@RequestParam("classificationName") String classificationName){
        List<HotelClassification> results = hotelClassificationService.getAllClassIfication();
        //这里我们对最大的分类数进行一个限制;
        if (results.size() >= ClassificationConst.MAX_CATEGORIES){
            return new ResultVO<String>(ResultVO.FAILED, ClassificationConst.MORE_THAN_CATEGORIES,ResultVO.NO_DATA);
        }
        hotelClassificationService.insertHotelClassification(classificationName);
        return new ResultVO<String>(ResultVO.FAILED,ClassificationConst.SAVING_CLASSIFICATION_INFORMATION_SUCCEEDED,ResultVO.NO_DATA);

    }

    @RequestMapping("/delete/hotel/classification")
    @ResponseBody
    public ResultVO deleteHotelClassification(@RequestParam("itemId") String itemId){
        hotelClassificationService.deleteHotelClassification(itemId);
        return new ResultVO<String>(ResultVO.SUCCESS,ClassificationConst.DELETE_CLASSIFICATION_INFORMATION_SUCCEEDED,ResultVO.NO_DATA);
    }

}
